/*****This do_file requires restricted use or proprietary data: NLSY79(geocoded) and NSSE***/ 

clear 
set mem 400m
set more off
cd c:\data\timeuse
use talent_main, clear

/*The following line references restricted NLSY79 geocoded data*/
append using C:\data\restricted\nlsymerge
gen dec81=(weight81!=.)
drop if hrstudy==.

/* Oaxaca: Talent - NLSY79  */
egen wt1=sum(wtb01)
egen wt2=sum(weight81)
gen wtbig = wtb01/wt1 
replace wtbig = weight81/wt2 if !missing(weight81) 
gen hrsworkd=(hrswork==.)
replace hrswork=0 if hrsworkd==1
gen rel_age_d=(rel_age==.)
replace rel_age=0 if rel_age_d==1
gen femaled=(female==.)
replace female=0 if femaled==1
gen fathed_d=(fathed==.)
replace fath_hs =0 if fathed_d==1
replace fath_col =0 if fathed_d==1
gen raced=0
replace raced=1 if missing(black)|missing(white)|missing(asian)| missing(hisp)
replace black=0 if raced==1
replace asian=0 if raced==1 
replace white=0 if raced==1
replace hisp=0 if raced==1
gen majord=(majorgroup==.)
replace raced=1 if black==0&white==0&asian==0&dec81==1
replace carnegie=. if carnegie>32
tabulate carnegie, gen(cardum)

reg hrstudy female rel_age black asian fath_hs fath_col  raced rel_age_d fathed_d [aw=wtbig] if dec81==0
estimates store y1960a
reg hrstudy female rel_age black asian fath_hs fath_col  raced rel_age_d fathed_d [aw=wtbig] if dec81==1
estimates store y1980a
/* Table 5, Col 1 */
oaxaca y1960a y1980a, weight(1 0)


/*Table 4, Col 1, 2*/
use talent_main, clear
sum hrstudy work1 white black female fath_col [aw=wtb01] 
sum hrstudy work1 white black female fath_col [aw=wtb01 ] if carnegie==15|carnegie==16 
sum hrstudy work1 white black female fath_col [aw=wtb01] if carnegie==21|carnegie==22
sum hrstudy work1 white black female fath_col [aw=wtb01] if carnegie==31

sum hrstudy work1 white black female fath_col [aw=wtb01] if nsse==1
sum hrstudy work1 white black female fath_col [aw=wtb01 ] if nsse==1&(carnegie==15|carnegie==16 )
sum hrstudy work1 white black female fath_col [aw=wtb01] if nsse==1&(carnegie==21|carnegie==22)
sum hrstudy work1 white black female fath_col [aw=wtb01] if nsse==1&carnegie==31

/* To get institution counts: */
collapse count_c hrstudy carDR carMas carBacLib nsse, by(cccode)
tab carDR
tab carMas 
tab carBacLib 
tab nsse
tab carDR if nsse==1
tab carMas if nsse==1
tab carBacLib if nsse==1


use talent_main, clear
keep if nsse==1
/*the follwoing line references restricted use NSSE data */
append using C:\data\restricted\ncore
egen wt1n_=sum(wtb01)
egen wt2n_=sum(wgt)
gen wtbign_ = wtb01/wt1n_ 
replace wtbign_ = wgt/wt2n_ if !missing(wgt) 
replace dec04=0 if dec04==.
drop if hrstudy==.
/* Table 2 Col 5,6*/
sum hrstudy hrswork [aw=wtbign_] if dec04==0 
gen hrsworkd=(hrswork==.)
replace hrswork=0 if hrsworkd==1
gen rel_age_d=(rel_age==.)
replace rel_age=0 if rel_age_d==1
gen raced=0
gen fathed_d=(fathed==.)
replace fath_hs =0 if fathed_d==1
replace fath_col =0 if fathed_d==1
replace raced=1 if missing(black)|missing(white)|missing(asian)| missing(hisp)
replace black=0 if raced==1
replace asian=0 if raced==1
replace hisp=0 if raced==1
replace raced=1 if black==0&white==0&asian&dec04==1
replace dec04=0 if dec04==.
*drop if fathed_d==1&dec04==0
replace carnegie=. if carnegie>32
tabulate carnegie, gen(cardum)

/* Table 5, Col 5,6: Oaxaca freshman to freshman comparisons */
drop if classran>1 &dec04==1
reg hrstudy rel_age female black asian fath_hs fath_col raced rel_age_d fathed_d [aw=wtbign_] if dec04==0
estimates store y1960
reg hrstudy rel_age female black asian fath_hs fath_col raced rel_age_d fathed_d [aw=wtbign_] if dec04==1
estimates store y2004
oaxaca y1960 y2004, weight(1 0)


use talent_main, clear
/*Table 6 Column 1 */
reg hrstudy [pw=wtb01] 
outreg using pol1.xls , replace 
reg hrstudy [pw=wtb01] if work==0
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==1
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==2
outreg using pol1.xls, append 

reg hrstudy [pw=wtb01] if fath_nohs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_hs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_col==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if female==0
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if female==1
outreg using pol1.xls , append 


reg hrstudy [pw=wtb01] if white==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if asian==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if black==1
outreg using pol1.xls , append 


reg hrstudy [pw=wtb01] if majorgroup==1
outreg using pol2.xls , replace 
reg hrstudy [pw=wtb01] if majorgroup==2
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==3
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==4
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==5
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==6
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==7
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==8
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==9
outreg using pol2.xls, append 

reg hrstudy [pw=wtb01] if carnegie==15|carnegie==16
outreg using pol3.xls , replace 
reg hrstudy [pw=wtb01] if carnegie==21|carnegie==22
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if carnegie==31
outreg using pol3.xls, append 
reg hrstudy [pw=wtb01] if carnegie==32
outreg using pol3.xls, append 

/*Table 6 Column 5 */
keep if nsse==1
reg hrstudy [pw=wtb01] 
outreg using pol1.xls , replace 
reg hrstudy [pw=wtb01] if work==0
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==1
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==2
outreg using pol1.xls, append 

reg hrstudy [pw=wtb01] if fath_nohs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_hs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_col==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if female==0
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if female==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if white==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if asian==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if black==1
outreg using pol1.xls , append 


reg hrstudy [pw=wtb01] if majorgroup==1
outreg using pol2.xls , replace 
reg hrstudy [pw=wtb01] if majorgroup==2
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==3
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==4
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==5
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==6
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==7
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==8
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==9
outreg using pol2.xls, append 

reg hrstudy [pw=wtb01] if carnegie==15|carnegie==16
outreg using pol3.xls , replace 
reg hrstudy [pw=wtb01] if carnegie==21|carnegie==22
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if carnegie==31
outreg using pol3.xls, append 
reg hrstudy [pw=wtb01] if carnegie==32
outreg using pol3.xls, append 

/*The following line references restricted NSSE proprietary data*/
use C:\data\restricted\ncore, clear
rename wgt wtb01
/replace hrstudy=hrstudy+1.12  framing adjustment*/

/*Table 6 , Column 6*/
reg hrstudy [pw=wtb01] 
outreg using pol1.xls , replace

reg hrstudy [pw=wtb01] if work==0
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==1
outreg using pol1.xls , append 
reg hrstudy [pw=wtb01] if work==2
outreg using pol1.xls, append 

reg hrstudy [pw=wtb01] if fath_nohs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_hs==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if fath_col==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if female==0
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if female==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if white==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if asian==1
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if black==1
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if satv<540
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if satv>=540 & satv<=620
outreg using pol1.xls , append 
reg hrstudy  [pw=wtb01] if satv>620
outreg using pol1.xls , append 

reg hrstudy [pw=wtb01] if majorgroup==1
outreg using pol2.xls , replace
reg hrstudy [pw=wtb01] if majorgroup==2
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==3
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==4
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==5
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==6
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==7
outreg using pol2.xls, append 
reg hrstudy [pw=wtb01] if majorgroup==8
outreg using pol2.xls , append 
reg hrstudy [pw=wtb01] if majorgroup==9
outreg using pol2.xls, append 

reg hrstudy [pw=wtb01] if carnegie==15|carnegie==16
outreg using pol3.xls , replace
reg hrstudy [pw=wtb01] if carnegie==21|carnegie==22
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if carnegie==31
outreg using pol3.xls, append 
reg hrstudy [pw=wtb01] if carnegie==32
outreg using pol3.xls, append 

reg hrstudy [pw=wtb01] if satvslow==1
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if satvsmid==1
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if satvshi==1
outreg using pol3.xls , append 

gen size=enr*4
reg hrstudy [pw=wtb01] if size<2500
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if size>=2500 & size <=7500
outreg using pol3.xls , append 
reg hrstudy [pw=wtb01] if size >7500
outreg using pol3.xls , append 



